<template>
  <div class="value-page">
    <div class="fixed-btn">
      <a-button type="primary" @click="doShowAll()">{{showAll?'隐藏局部':'显示全部'}}</a-button>
    </div>
    <div class="question-list">
      <div v-for="group in questionList">
        <ul v-for="page in group">
          <question-audit-list
            :question-list-data="page"
            :project-build-id="projectBuildId"
            :show-all="showAll"
            @showAttach="showAttach"
            @downLoadAttach="downLoadAttach"
          ></question-audit-list>
        </ul>
      </div>
      <div style="widht: 80%; height: 30px">
        <img src="@/assets/category.png" alt="" />
        <span>&nbsp;&nbsp;<b>评定结果</b></span>
      </div>
      <div class="judge-result">
        <div style="width: 60%; border-right: 1px solid rgb(237, 237, 237)">
          <b>项目立项评定结果</b>&nbsp;&nbsp;&nbsp;&nbsp; 项目等级：<span class="result-show"
            ><b>{{ projectLevel }}</b></span
          >&nbsp;&nbsp;&nbsp;&nbsp; X(创新点)得点：<span class="result-show"
            ><b>{{ projectGradePoint }}分</b></span
          >&nbsp;&nbsp;&nbsp;&nbsp;
        </div>
        <div style="width: 40%; border-right: 1px solid rgb(237, 237, 237)">
          <b>Y(基础点)得分</b>&nbsp;&nbsp;&nbsp;&nbsp;
          <span class="result-show"
            ><b>{{ projectGradePointBasic }}分</b></span
          >
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import $ from 'jquery'
import '@/utils/upload.install.js'
import { getParamValFromUrl } from '@/utils/common.js'
import { getAction, previewAttach } from '@/api/manage'
import Vue from 'vue'
import { ACCESS_TOKEN, USER_INFO } from '@/store/mutation-types'
import { formatFileSize, endWith } from '@/utils/common.js'

export default {
  name: 'QuestionAuditPage',
  components: {
    QuestionAuditList: () => import('@/components/tools/QuestionAuditList'),
  },
  data() {
    return {
      tabbarstyle: {
        backgroundColor: '#fff',
        position: 'fixed',
        height: 'unset',
      },
      questionList: [],
      url: {
        queryTestValueById: '/projectBuild/queryTestValueById',
        downLoadBatch: '/common/downLoadBatch',
      },
      projectBuildId: '',
      projectBuild: {},
      showAll: false,
      //评定结果
      projectLevel: '',
      projectGradePoint: 0,
      projectExpectReward: 0,
      projectGradePointBasic: 0,
      auditRerunUserId: '',
    }
  },
  mounted() {
    if (this.parentProjectBuildId == '') {
      this.projectBuildId = getParamValFromUrl('projectBuildId')
    } else {
      this.projectBuildId = this.parentProjectBuildId
    }
    this.queryTestValue(this.projectBuildId)
  },
  created() {},
  computed: {},
  props: {
    parentProjectBuildId: {
      Type: String,
      default: '',
    },
    version:{
      Type: String,
      default: ''
    }
  },
  methods: {
    showAttach(record) {
      var id = record.id
      var uploader = record.uploader
      var fileName = record.fileName
      if (!this.checkPermisson(uploader) && !this.projectBuild.projectSubTypeAdmin) {
        this.$message.warning('仅有该项目管理员、附件上传人、项目经理、副经理可以查看!')
        return
      }
      //以rar、zip、dwg结尾的文件，直接下载不预览
      if (
        endWith(fileName, 'rar') ||
        endWith(fileName, 'zip') ||
        endWith(fileName, 'dwg') ||
        endWith(fileName, 'tgz')
      ) {
        this.doDownLoadBatch(id)
        return
      }
      let params={
        id:id,
        ftpKey:'ftp'
      };
      previewAttach(params).then(result=>{
        const url=URL.createObjectURL(result)
        if (this.projectBuild.projectClass == '40' || this.projectBuild.projectClass == '61') {
          window.open(process.env.BASE_URL+'/pdf/web/normalViewer.html?file=' + url)
        } else {
          window.open(process.env.BASE_URL+'/pdf/web/viewer.html?file=' + url)
        }
      }).catch(err => {
        this.$message.warning('下载文件失败');
      })
    },
    downLoadAttach(record){
      var id = record.id
      var uploader = record.uploader
      if (!this.checkPermisson(uploader) && !this.projectBuild.projectSubTypeAdmin) {
        this.$message.warning('仅有该项目管理员、附件上传人、项目经理、副经理可以下载!')
        return
      }
      this.doDownLoadBatch(id)
    },
    doDownLoadBatch(attachIds) {
      if (document.getElementById('_attachToolView_downloadfile_frame') == null) {
        var downloadFrame = $('<iframe id="_attachToolView_downloadfile_frame" style="display: none"></iframe>')
        downloadFrame.appendTo($('body'))
      }
      var iframe = document.getElementById('_attachToolView_downloadfile_frame')
      var href =
        this.API_BASE_URL +
        this.url.downLoadBatch +
        '?attachIds=' +
        attachIds +
        '&dbKey=Trd&ftpKey=ftp&token=' +
        Vue.ls.get(ACCESS_TOKEN)
      iframe.src = href
    },
    checkPermisson(uploader) {
      var projectManagers = this.projectBuild.projectManagers
      var assistantProjectManagers = this.projectBuild.assistantProjectManagers
      var currUser = Vue.ls.get(USER_INFO).username
      if (uploader == currUser) {
        return true
      }
      if (projectManagers == null || projectManagers.length == 0) {
        projectManagers = []
      }
      projectManagers = projectManagers.concat(assistantProjectManagers)
      if (projectManagers.indexOf(currUser) > -1) {
        return true
      }
      return false
    },
    doShowAll() {
      this.showAll = !this.showAll
    },
    //查询题目数据，初始化
    queryTestValue(projectBuildId) {
      var vm = this
      getAction(this.url.queryTestValueById, { id: projectBuildId,type:'XY',version: this.version }).then((res) => {
        var result = res.result
        if (result == null) {
          this.$message.warning(res.message)
        } else {
          vm.projectBuild = result;
          if (result.projectBuildTestVOList != null) {
            //编辑过，取已编辑信息
            result.projectBuildTestVOList.map((test) => {
              if (test.valueQuestions != null && test.valueQuestions.length > 0) {
                vm.questionList = vm.questionList.concat(test.valueQuestions)
              }
            })
            vm.projectLevel = result.projectLevel
            vm.projectGradePoint = result.projectGradePoint
            vm.projectExpectReward = result.projectExpectReward
            vm.projectGradePointBasic = result.projectGradePointBasic
            vm.auditRerunUserId = result.auditRerunUserId
          }
        }
        console.log('vm.questionList:' + JSON.stringify(vm.questionList))
      })
    },
  },
}
</script>
<style lang="less" scoped>
.value-page {
  ul,
  menu,
  dir {
    -webkit-margin-before: 0px;
    -webkit-margin-after: 0px;
    -webkit-padding-start: 0px;
  }
  width: 100%;
  // background-color: #f5f5f5;
  // padding-bottom: 70px;
  .judge-result {
    padding: 0px !important;
    margin-bottom: 15px;
    border: 1px solid rgb(237, 237, 237);
    height: 60px;
    background-color: #fff;
    div {
      height: 60px;
      line-height: 60px;
      text-align: center;
      float: left;
    }
    .result-show {
      font-size: 16px;
      color: red;
    }
  }

  .classify-header {
    color: #fff;
    .header-bg {
      height: 100px;
      background-image: url('../../assets/value-bg.png');
      background-size: contain;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      background-repeat: repeat-x;
      .header-step {
        padding: 35px 0 0 150px;
        font-size: 14px;
        display: flex;
        > div {
          flex: 1;
          display: flex;
          align-items: center;
          vertical-align: center;
          // justify-content: space-between;
          // padding-right: 20px;
          width: 16%;
        }
        i {
          font-style: normal;
          display: inline-block;
          text-align: center;
          width: 100%;
        }
        .step-style {
          display: inline-block;
          width: 80px;
          height: 6px;
          border-radius: 10px 0 0 10px;
          // margin-right: 35px;
          position: relative;
          &::before {
            position: absolute;
            content: '';
            right: -2px;
            top: -80%;
            width: 16px;
            height: 16px;
            border-radius: 50%;
          }
        }
        .step-unfinished {
          color: #fff;
          .step-style {
            background-color: #fff;
            &::before {
              background-color: inherit;
            }
          }
        }
        .step-finished {
          color: #6ca8f8;
          .step-style {
            background-color: #6ca8f8;
            &::before {
              background-color: inherit;
            }
          }
        }
      }
      .header-warn {
        padding: 0 150px;
        position: absolute;
        bottom: 12%;
        // left: 10%;
        font-weight: 600;
        img {
          width: 18px;
          vertical-align: middle;
          margin-right: 5px;
          margin-top: -2px;
        }
        span {
          font-weight: normal;
          font-size: 10px;
          opacity: 0.8;
        }
      }
    }
  }
  input {
    margin: 5px 0;
  }
  .question-list {
    padding: 20px 100px 50px 100px;
    height: fit-content;
    background-color: #f5f5f5;
    .btnBox {
      text-align: center;
      display: block;
      border: unset;
      & /deep/ .ant-btn {
        border: unset;
        border-radius: unset;
        margin: 0 20px;
        width: 150px;
      }
      & /deep/ .ant-btn-primary {
        background-color: #24508c;
      }
    }
    /deep/ .ant-tabs-nav-container {
      margin-top: 0;
    }
    /deep/ .ant-tabs .ant-tabs-left-bar {
      border-right: none;
    }
    /deep/ .ant-tabs .ant-tabs-left-bar .ant-tabs-tab {
      text-align: left;
      width: 201px;
      border-bottom: 1px dashed #e9e9e9;
      margin: 0;
      padding: 15px 25px;
      transition: none;
      &::after {
        content: '';
        background: url('../../assets/unselected.png') no-repeat;
        width: 6px;
        height: 10px;
        float: right;
        margin-top: 5px;
      }
    }
    /deep/ .ant-tabs-nav .ant-tabs-tab:active,
    /deep/ .ant-tabs-nav .ant-tabs-tab-active {
      color: #fff;
      background-color: #4790bb;
      &::after {
        content: '';
        background: url('../../assets/selected.png') no-repeat;
      }
    }
    /deep/ .ant-tabs .ant-tabs-left-bar .ant-tabs-tab:focus {
      &::after {
        content: '';
        background: url('../../assets/selected.png') no-repeat;
      }
    }
    /deep/ .ant-tabs-ink-bar {
      background-color: inherit;
      opacity: 0;
    }
    /deep/.ant-tabs .ant-tabs-left-content {
      border: none;
      max-width: 80%;
    }
    /deep/.ant-tabs .ant-tabs-left-content {
      overflow: unset;
    }
  }
}
.fixed-btn{height: 30px; position: fixed;top: 245px; left: 30px;z-index:2;opacity:0.8;}
@media (max-width: 1080px){
  div.fixed-btn{left: 5px}
}
</style>